package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.module.push.provider.service.JPushService;
import com.meida.module.user.provider.service.AppUserService;
import com.meida.msg.client.entity.MsgContent;
import com.meida.msg.provider.handler.SendMsgHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SysSendMsgHandler implements SendMsgHandler {

    @Autowired
    private JPushService jPushService;

    @Autowired
    private AppUserService appUserService;

    @Override
    public void sendMsg(MsgContent msgContent) {
        Integer msgState = msgContent.getMsgState();
        if (msgState == 1) {
            EntityMap extra = new EntityMap();
            extra.put("msgType", "SystemMsg");
            extra.put("msgUserId", "");
            String msgTitle = msgContent.getMsgTitle();
            String content = msgContent.getMsgContent();
            List<String> userIdList = appUserService.queryAllSetSystemMsgNotice();
            jPushService.sendByListTokey(userIdList, msgTitle, msgTitle, content, extra);
        }
    }

}
